<template>
  <div v-if="this.$store.state.user.id">
    <el-dropdown @command="handleCommand">
      <span class="el-dropdown-link">
        当前登录用户：{{this.$store.state.user.id}} --- {{this.$store.state.user.name}}<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
  <div v-else>
    <el-button @click="handleCommand">登录</el-button>
  </div>
</template>

<script>


export default {
  name: "Header",
  data() {
    return {
     
    }
  },
  mounted(){
    console.log(1111)
    if(JSON.parse(sessionStorage.getItem("user"))){
      console.log(JSON.parse(sessionStorage.getItem("user")))
      this.$store.dispatch("setUser",JSON.parse(sessionStorage.getItem("user")))
    }
  },
  methods: {
    handleCommand(cmd){
      this.$store.dispatch("setUser",{})
      sessionStorage.removeItem("user");
      this.$router.push("/login")

    }
  }
    
}
</script>

<style scoped></style>
